11. Exercise: Make a Preference Fragment

Exercise Code

In this exercise, you will be creating a SettingsFragment.

Exercise: T06.02-Exercise-MakeAPreferenceFragment

Make a Preference Fragment Exercise Two

Now it's your turn, follow the TODOs in the code comments and check them here once complete

SOLUTION:
  • Add the gradle dependency for the support preference fragment
  • Create the SettingsFragment class that extends PreferenceFragmentCompat
  • Create the pref_visualizer in res->xml
  • Add a CheckBoxPreference to the preference
  • Call addPreferencesFromResource method to add the preference file
  • Add a preference theme to styles.xml